package controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import model.DataTableObject;
import model.Manufacturer;
import model.User;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.SessionAttributes;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import dao.ManufacturerDAO;
import dao.UserDAO;



@Controller
@RequestMapping("PagesUI")
public class DataController {
	
	@Resource(name = "manufacturerDAO")
	private ManufacturerDAO manuDao;
	
	@RequestMapping(value = "/dataManu", method= RequestMethod.GET)
	@ResponseBody
	public String hello(HttpSession session){
//		List<Manufacturer> myProduct = productDao.getAllProduct();
//		DataTableObject dataTableObj= new DataTableObject();
//		dataTableObj.setAaData(myProduct);
//		Gson gson = new GsonBuilder().setPrettyPrinting().create();
//		String data=gson.toJson(dataTableObj);
//		return data;
		System.out.println("loc");
		User myuser = (User) session.getAttribute("userInfo");
		System.out.println(myuser.getPassword());
		
		List<Manufacturer> myManufacture = manuDao.getManuFactureByUId(myuser.getId());
		DataTableObject<Manufacturer> dataTableObj= new DataTableObject<Manufacturer>();
		dataTableObj.setAaData(myManufacture);
		Gson gson = new GsonBuilder().setPrettyPrinting().create();
		String data=gson.toJson(dataTableObj);
		System.out.println("data: "+data);
		return data;
	}
}
